<div id="horizontal-form">
	<form class="form-horizontal" role="form" action="${saveUrl}" method="post" responseType="JSON" role="form" id="editForm_${serializeNum}"
		  data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
		  data-bv-message="This value is not valid"
		  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
		  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
		  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
		<input type="hidden" name="formKey" value="${formKey}">
		<input type="hidden" name="formToken" value="${formToken}">
		<input type="hidden" id="dataId_${serializeNum}" name="id" value="${smp.id}">
		<input type="hidden" name="weight" value="${smp.weight}">
		<input type="hidden" name="createUserId" value="${smp.createUserId}">
		<div class="form-group">
			<label for="pId" class="col-sm-2 control-label no-padding-right">父菜单</label>
			<div class="col-sm-10">
				<select  name="pId" class="selectpicker_${serializeNum}" data-live-search="true" style="width: 90%;">
					<optgroup label="选择所属分组" data-icon="icon-ok">
						<option value="">无</option>
						<#list pId_datasources as datasources >
							<option value="${datasources.id}">${datasources.name}</option>
						</#list>
					</optgroup>
				</select>
				<script type="text/javascript">
					$("[name='pId']").val("${smp.pId}");
				</script>
			</div>
		</div>
		<div class="form-group">
			<label for="name" class="col-sm-2 control-label no-padding-right">显示名称</label>
			<div class="col-sm-9">
				<input type="text" class="form-control" name="name" required="required" value="${smp.name}" placeholder="显示名称">
			</div>
		</div>
		<div class="form-group">
			<label for="handlePermissionIdentifier" class="col-sm-2 control-label no-padding-right">权限标识</label>
			<div class="col-sm-7">
				<input required="required"  type="text" class="form-control" name="handlePermissionIdentifier" required="required" value="${smp.handlePermissionIdentifier}" placeholder="操作权限标识">
			</div>
			<div class="col-sm-1">
				<a class="btn btn-success" onclick="genHandlePermissionIdentifier()">生成</a>
			</div>
			<div class="col-sm-12">
				<p class="red">注意：操作权限标识符将参与该菜单权限下所有操作权限的是实际编码,固在所有菜单权限下此标识应保持唯一,且不允许做二次修改</p>
			</div>
		</div>
		<div class="form-group">
			<label for="icon" class="col-sm-2 control-label no-padding-right">显示图标</label>
			<div class="col-sm-9">
				<input type="text" class="form-control" name="icon" value="${smp.icon}" placeholder="显示图标">
			</div>
		</div>
		<div class="form-group">
			<label for="url" class="col-sm-2 control-label no-padding-right">链接地址</label>
			<div class="col-sm-9">
				<textarea style="width: 100%; height: 100px; resize: none;" required="required"  class="form-control" name="url"placeholder="链接地址">${smp.url}</textarea>
			</div>
		</div>
		<div class="form-group">
			<label for="isForbidden" class="col-sm-2 control-label no-padding-right">是否禁用</label>
			<div class="col-sm-9">
				<input type="hidden" name="isForbidden" value=${(smp.isForbidden???string(smp.isForbidden?string('true','false'),'false'))!'false'}>
				<label>
					<input class="checkbox-slider yesno" data-target-form-id="editForm_${serializeNum}" data-target-input-name="isForbidden" type="checkbox" ${(smp.isForbidden???string(smp.isForbidden?string('checked',''),''))!''}>
					<span class="text"></span>
				</label>
				<script type="text/javascript">
                    var tim=setTimeout(function(){
                        var isForbidden="${(smp.isForbidden???string(smp.isForbidden?string('true','false'),'false'))!'false'}";
                        $("#editForm_${serializeNum} [name='isForbidden']").val(isForbidden);
                        clearTimeout(tim);
                    },100);
				</script>
			</div>
		</div>
		<div class="form-group">
			<label for="weight" class="col-sm-2 control-label no-padding-right" style="margin-right: 5px;">同级权重</label>
			<div class="col-sm-9">
				<p style="margin-top: 7px;">${smp.weight}</p>
			</div>
		</div>
		<div class="form-group">
			<label for="createTime"
				class="col-sm-2 control-label no-padding-right">创建时间</label>
			<div class="col-sm-9">
				<p style="margin-top: 7px;">${smp.createTime}</p>
			</div>
		</div>
		<div class="form-group">
			<label for="createUser" class="col-sm-2 control-label no-padding-right">创建人Id</label>
			<div class="col-sm-10">
				<p style="margin-top: 7px;">${smp.adminUser.userName}<#if smp.adminUser.realName>(${smp.adminUser.realName})</#if></p>
			</div>
		</div>
        <div class="form-title"></div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
				<button type="submit" id="editFormSubmitBtn_${serializeNum}"class="btn btn-danger" >修 改</button>
			</div>
		</div>
	</form>
</div>
<script src="assets/js/select2/select2.js"></script>
<script>
    $(".selectpicker_${serializeNum}").select2();

    //初始化表单验证
    inintValidatorForm($("#editForm_${serializeNum}"));

	$(document).on("ajaxSubmitCallback","#editForm_${serializeNum}",function(event,data){
        if(data.resCode==200){
            logger.info(data.resMsg,true);
            var handlePermissionIdentifier=$("#editForm_${serializeNum} [name='handlePermissionIdentifier']");
            var handlePermissionIdentifierVal=handlePermissionIdentifier.val();
            var isForbidden=$("#editForm_${serializeNum} [name='isForbidden']").val();
            resetValidatorForm($("#editForm_${serializeNum}").get(0));
            handlePermissionIdentifier.val(handlePermissionIdentifierVal);
            $("#editForm_${serializeNum} [name='isForbidden']").val(isForbidden);
            var radio=$("#editForm_${serializeNum} [data-target-input-name='isForbidden']");
            if(isForbidden=="true"){
                radio.attr("checked","checked");
            }else{
                radio.removeAttr("checked");
            }
            //更新token信息
            $("#editForm_${serializeNum} [name='formKey']").val(Math.randomStr());
            $("#editForm_${serializeNum} [name='formToken']").val(Math.randomStr());
        }else{
            logger.error(data.resMsg);
        }
	});

	/**
	 * 根据菜单名称生成菜单操作权限唯一标识
	 */
	function genHandlePermissionIdentifier(){
		var menuName=$("#editForm_${serializeNum} [name='name']");
		if(!menuName.val()){
			alert("请先输入菜单名!");
			menuName.focus();
			return ;
		}
		ajaxRequest("sysMenuPermissionsController/genHandlePermissionIdentifier.do?timer="+new Date().getTime(), {menuName:menuName.val()}, function(result) {
			$("#editForm_${serializeNum} [name='handlePermissionIdentifier']").val(result.data);
		},
		function(XMLHttpRequest, textStatus, errorThrown) {
			ajaxError(errorThrown);
		},"GET", "JSON");
	}
</script>